package com.lcn.comm.domain;

import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * <p>类说明</p>
 *
 * @author 张峰 zfvip_it@163.com
 * @create: 2017-12-27 13:14
 */
public class TxGroupManager {

    private static TxGroupManager instance = null;

    private static Map<String, TxGroup> txGroupMap = new ConcurrentHashMap<String, TxGroup>();

    private TxGroupManager() {
    }

    public static TxGroupManager getInstance() {
        if (instance == null) {
            synchronized (TxGroupManager.class) {
                if (instance == null) {
                    instance = new TxGroupManager();
                }
            }
        }
        return instance;
    }

    /**
     * 添加事务组
     *
     * @param txGroup
     */
    public void addGroup(TxGroup txGroup) {
        txGroupMap.put(txGroup.getGroupId(), txGroup);
    }

    /**
     * 获取事务组
     *
     * @param groupId
     */
    public TxGroup getGroup(String groupId) {
        return txGroupMap.get(groupId);
    }

    /**
     * 删除事务组
     *
     * @param groupId
     */
    public void removeGroup(String groupId) {
        if (StringUtils.isNotEmpty(groupId)) {
            txGroupMap.remove(groupId);
        }
    }
}
